package edu.whu;

import edu.whu.dao.UserDao;
import edu.whu.dao.impl.UserDaoImpl;
import edu.whu.proxy.LogHandler;

import java.lang.reflect.Proxy;

public class DynamicProxyApplication {

    public static void main(String[] args) {
        //被拦截对象
        UserDao target= new UserDaoImpl();

        //创建动态代理对象
        UserDao userDao= (UserDao) Proxy.newProxyInstance(
                DynamicProxyApplication.class.getClassLoader(),
                new Class[] {UserDao.class},
                new LogHandler(target));

        //调用动态代理对象
        String result = userDao.save("jia");
        System.out.println(result);
    }


}
